package 算法.贪心算法;
//https://leetcode-cn.com/problems/minimum-deletion-cost-to-avoid-repeating-letters/
public class 避免重复字母的最小删除成本 {
    public static void main(String[] args) {
        System.out.println(minCost("abaac",new int[]{1,2,3,4,5}));
    }
    public static int minCost(String s, int[] cost) {
        int minP = 0;
        int r = 0;
        int l;
        int k = s.length();
        for(l = 1; l < k; l++){
            int n1 = s.charAt(r);
            int n2 = s.charAt(l);
            if(s.charAt(r) == s.charAt(l)){
                n1 = cost[r];
                n2 = cost[l];
                if(n1 > n2){
                    minP += n2;
                }else {
                    minP += n1;
                    r = l;
                }
            }else {
                r = l;
            }
        }
        return minP;
    }

}
